// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------
// Modification history:
// feature: listener code decoupling
// feature: simplify xml profile
// feature: support multiple sending based on topic
// feature: change idl check from md5 to crc16
// ------------------------------------------------------------------

#ifndef XMLPARSER_TOPICATTRIBUTES_H_
#define XMLPARSER_TOPICATTRIBUTES_H_

#include <deps/common/fixed_size_string.hpp>
#include <deps/common/Types.h>
#include <xmlparser/qos/XMLTopicQos.hpp>
#include <deps/attributes/BaseTopicAttributes.h>

namespace vbsutil {
namespace xmlparser {

/**
 * Class TopicAttributes, used by the user to define the attributes of the topic associated with a
 * Publisher or Subscriber.
 * @ingroup ERTPS_ATTRIBUTES_MODULE
 */

class TopicAttributes : public BaseTopicAttributes {
 public:
    /**
     * Default constructor
     */
    TopicAttributes() : BaseTopicAttributes() {}

    //! Constructor, you need to provide the topic name and the topic data type.
    TopicAttributes(const char* const name, const char* const dataType,
                    const xmlparser::TopicKind_t tKind = xmlparser::NO_KEY)
        : BaseTopicAttributes(name, dataType, tKind) {}

    // virtual ~TopicAttributes() {}

    bool operator==(const TopicAttributes& b) const {
        return (this->topicKind == b.topicKind) && (this->topicName == b.topicName) &&
               (this->topicDataType == b.topicDataType) && (this->qos.history() == b.qos.history());
    }

    //! Topic Qos Profile
    TopicQos qos;
};

#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC

/**
 * Check if two topic attributes are not equal
 * @param t1 First instance of TopicAttributes to compare
 * @param t2 Second instance of TopicAttributes to compare
 * @return True if the instances are not equal. False if the instances are equal.
 */
bool inline operator!=(const TopicAttributes& t1, const TopicAttributes& t2) {
    if ((t1.topicKind != t2.topicKind) || (t1.topicName != t2.topicName) || (t1.topicDataType != t2.topicDataType) ||
        (t1.qos.history().kind != t2.qos.history().kind) ||
        ((t1.qos.history().kind == vbsutil::xmlparser::HistoryQosPolicyKind::KEEP_LAST_HISTORY_QOS) &&
         (t1.qos.history().depth != t2.qos.history().depth))) {
        return true;
    }
    return false;
}
#endif

}  // namespace xmlparser
}  // namespace vbsutil

#endif
